package com.yanqu.road.server.cmd.activity.peakseacraft.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.PeakSeacraftProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.peakseacraft.PeakSeacraftGroup;
import com.yanqu.road.server.manger.activity.peakseacraft.PeakSeacraftMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.union.GameUnionActivityGroupMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;


/**
 */
@Cmd(code = GameProtocol.S_PEAK_SEACRAFT_CHAT_BROADCAST_FROM_CROSS, desc = "战场聊天广播")
public class PeakSeacraftChatBroadcastFromCrossCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        WorldMessageProto.WorldMessageTempMsg chatMsg = WorldMessageProto.WorldMessageTempMsg.parseFrom(packet.getBytes());
        int value = Integer.valueOf(chatMsg.getExtraParams());
        int area = value / 100;
        int group = value % 100;
        int unionGroup = chatMsg.getGroupId();
        PeakSeacraftGroup peakSeacraftGroup = PeakSeacraftMgr.getPeakSeacraftGroup(unionGroup);
        if (peakSeacraftGroup == null) {
            return;
        }
        for (GamePlayer onlinePlayer : GamePlayerMgr.getAllOnlinePlayer()) {
            int groupId = GameUnionActivityGroupMgr.getGroupId(peakSeacraftGroup.getActivityId(), onlinePlayer.getUserId());
            if (groupId != unionGroup) {
                continue;
            }
            onlinePlayer.sendPacket(ClientProtocol.U_WORLD_MESSAGE_SYNC, chatMsg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {
    }
}
